//引入四个常用通用样式
import "../../assets/css/index.less";
//引入当前样式表
import "../home/home.less";
//字体图标
import "../../assets/fonts/iconfont.css";
//引入分装好的axios
import {
	postinfoReq,
	postclockInReq,
	postclockInInfoReq,
} from "../../api/user.js";
//引入节点封装函数
let dom = require("../../util/dom.js");

//引入swiper
import Swiper from "swiper/bundle";
import "swiper/css/bundle";
const swiper = new Swiper(".swiper", {
	// Optional parameters
	direction: "horizontal",
	//循环播放
	loop: true,
	//自动播放
	autoplay: {
		delay: 3000,
		stopOnLastSlide: false,
		disableOnInteraction: false,
	},

	// If we need pagination
	pagination: {
		el: ".swiper-pagination",
	},
});
dom.box("home");
//获取客户信息
async function info() {
	let res = await postinfoReq();
	// console.log(res);
	if (res.data.errno === 0) {
		dom.$("#Ranking").innerHTML = res.data.data.ranking;
		dom.$("#numhonors").innerHTML = res.data.data.badges;
	}
}
info();
//获取打卡信息
async function clockInInfo() {
	let res = await postclockInInfoReq();
	if (res.data.data.isClockIn == true) {
		dom.$("#Punchbtn").innerHTML = "今日已打卡";
	}
	if (res.data.data.isClockIn == false) {
		dom.$("#Punchbtn").innerHTML = "今日打卡";
	}
	if (res.data.errno === 0) {
		dom.$("#Punch").innerHTML = res.data.data.clockCount;
	}
}
clockInInfo();
//点击打卡
dom.$("#Punchbtn").addEventListener("click", async () => {
	let res = await postclockInReq();
	let { errno } = res.data;
	if (errno === 0) {
		dom.$("#Punchbtn").innerHTML = "今日打卡";
		dom.$("#Punch").textContent += 1;
	}
	{
		dom.$("#Punchbtn").innerHTML = "今日已打卡";
	}
});
